package com.zhang.yygh.user.controller.admin;

import com.atguigu.yygh.model.user.UserInfo;
import com.atguigu.yygh.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhang.yygh.common.result.R;
import com.zhang.yygh.user.service.UserInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/userinfo")
public class AdminUserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    //用户列表（条件查询带分页）
    @GetMapping("{pageNum}/{limit}")
    public R getUserInfoPageByQueryCondition(@PathVariable Integer pageNum,
                                             @PathVariable Integer limit,
                                             UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> page=userInfoService.getUserInfoPageByQueryCondition(pageNum,limit,userInfoQueryVo);
        return R.ok().data("page",page);
    }

    @ApiOperation(value = "锁定")
    @PutMapping("lock/{id}/{status}")
    public R lock(
            @PathVariable("id") Long id,
            @PathVariable("status") Integer status){
        userInfoService.lock(id, status);
        return R.ok();
    }

    @ApiOperation(value = "详情")
    @GetMapping("show/{id}")
    public R show(@PathVariable("id") Integer id){
        Map<String,Object> map=userInfoService.show(id);
        return R.ok().data(map);
    }

    //认证审批
    @GetMapping("approval/{userId}/{authStatus}")
    public R approval(@PathVariable Long userId,@PathVariable Integer authStatus) {
        userInfoService.approval(userId,authStatus);
        return R.ok();
    }
}
